<template>
  <div class="screen-data-wrapper">
    <div class="screen-column">
      <div class="row-box">
        <div class="row-box-left">
          <div class="column-box">
            <div class="column-title">客户信息</div>
            <div class="chart1">
              <chart1 />
            </div>
          </div>
          <div class="column-box">
            <div class="column-title">硬件产品种类</div>
            <div class="chart2">
              <chart2 />
            </div>
          </div>
        </div>
        <div class="row-box-right">
          <div class="column-box">
            <div class="column-title">经销商信息</div>
            <div class="column-content">
              <div class="chart3">
                <chart3 />
              </div>
              <div class="table-box">
                <div class="table-header">
                  <div class="table-th">排名</div>
                  <div class="table-th">经销商</div>
                  <div class="table-th">客户数量</div>
                </div>
                <div class="table-body">
                  <div class="table-row" v-for="(item, index) in tableData" :key="index">
                    <div class="table-cell">
                      <div class="no">{{ index + 1 }}</div>
                    </div>
                    <div class="table-cell">{{ item.name }}</div>
                    <div class="table-cell">{{ item.customers_count }}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="screen-column">
      <div class="column-box">
        <div class="column-title">订单效果展示</div>
        <div class="chart4">
          <chart4 />
        </div>
      </div>
    </div>
    <div class="screen-column">
      <div class="column-box">
        <div class="column-title">实验器材报修率</div>
        <div class="chart5">
          <chart5 />
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, computed } from "vue";
import chart1 from "./charts/chart1.vue";
import chart2 from "./charts/chart2.vue";
import chart3 from "./charts/chart3.vue";
import chart4 from "./charts/chart4.vue";
import chart5 from "./charts/chart5.vue";
import api from "@/api";
import { onMounted } from "vue";
import { useScreenStore } from "@/store/modules/screen";
const tableData = ref([]);
onMounted(() => {
  queryData();
});
const screenStore = useScreenStore();

const queryData = async () => {
  let res = await api.apiDashboardAdminDashboardDataPost({});
  console.log(res);

  // 将所有数据存储到screen store中
  screenStore.setScreenData({
    customer_province_dic: res.data.customer_province_dic, // 省份里的客户数量分布
    dealer_province_dic: res.data.dealer_province_dic, // 省份里的经销商数量分布
    customer_type_dic: res.data.customer_type_dic, // 客户分类数量分布
    instrument_category_dic: res.data.instrument_category_dic, // 实验仪器百科分类数量分布
    equipment_category_dic: res.data.equipment_category_dic, // 硬件产品种类
    orders: res.data.orders, // 订单效果展示
    equipments: res.data.equipments, // 实验器材报修率
    dealers: res.data.dealers // 经销商数据
  });

  // 保持原有的tableData赋值
  tableData.value = res.data.dealers;
};
</script>
<style lang="less" scoped>
.screen-data-wrapper {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  box-sizing: border-box;

  .screen-column {
    flex: 1;
    .row-box {
      display: flex;
      align-items: stretch;
      justify-content: space-between;
      height: 100%;

      @media screen and (max-width: 768px) {
        flex-direction: column;
      }

      .row-box-left {
        width: 390px;
        margin-right: 12px;
        display: flex;
        flex-direction: column;
        gap: 12px;
        
        .column-box {
          flex: 1;
        }
      }

      .row-box-right {
        flex: 1;
      }
    }

    .column-box {
      background: #ffffff;
      border-radius: 8px;
      padding: 16px;
      height: 100%;
      display: flex;
      flex-direction: column;

      .column-title {
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        font-size: 16px;
        color: #262626;
        line-height: 22px;
        text-align: left;
        font-style: normal;
        margin-bottom: 16px;
      }

      .column-content {
        display: flex;
        justify-content: space-between;
        flex: 1;
        gap: 20px;

        .chart3 {
          flex: 1;
          background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
          border-radius: 8px;
          padding: 12px;
          box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        .table-box {
          width: 280px;
          background: #ffffff;
          border-radius: 8px;
          padding: 16px;
          box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
          border: 1px solid #f0f0f0;

          .table-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
            padding: 12px 0;
            border-bottom: 2px solid #f0f0f0;
            background: linear-gradient(90deg, #fafbfc 0%, #f8f9fa 100%);
            border-radius: 6px;
            padding: 12px 16px;

            .table-th {
              font-family: PingFangSC, PingFang SC;
              font-weight: 600;
              font-size: 13px;
              color: #1f2937;
              line-height: 18px;
              text-align: left;
              font-style: normal;

              &:nth-child(1) {
                width: 40px;
                text-align: center;
              }

              &:nth-child(2) {
                width: 140px;
                text-align: left;
              }

              &:nth-child(3) {
                width: 80px;
                text-align: right;
              }
            }
          }

          .table-body {
            max-height: 300px;
            overflow-y: auto;
            
            .table-row {
              display: flex;
              justify-content: space-between;
              align-items: center;
              padding: 12px 16px;
              margin-bottom: 4px;
              border-radius: 6px;
              transition: all 0.2s ease;
              
              &:hover {
                background: linear-gradient(90deg, #f8fafc 0%, #f1f5f9 100%);
                transform: translateX(2px);
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
              }
              
              &:nth-child(odd) {
                background: #fafbfc;
              }

              .table-cell {
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                font-size: 14px;
                color: #374151;
                line-height: 20px;
                text-overflow: ellipsis;
                overflow: hidden;
                white-space: nowrap;

                &:nth-child(1) {
                  width: 40px;
                  text-align: center;
                }

                &:nth-child(2) {
                  width: 140px;
                  text-align: left;
                  font-weight: 500;
                }

                &:nth-child(3) {
                  width: 80px;
                  text-align: right;
                  color: #059669;
                  font-weight: 600;
                }

                .no {
                  display: inline-flex;
                  align-items: center;
                  justify-content: center;
                  width: 24px;
                  height: 24px;
                  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
                  color: white;
                  border-radius: 50%;
                  font-size: 12px;
                  font-weight: 600;
                  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
                }
              }
            }
          }
        }
      }

      .chart1,
      .chart2,
      .chart3,
      .chart4,
      .chart5 {
        flex: 1;
        min-height: 200px;
      }
    }
  }
}
</style>
